const {
  $util,
} = getApp();
Page({
  data: {
    page: 1,
    hasMore: true,
    nav: [{
      title: '未上报',
      id: 0,
    }, {
      title: '已上报',
      id: 1,
    }],
    ctype: 0, // 未上报 0，已上报 1
  },
  onLoad(opts) {
    this.setData(opts);
  },
  onShow() {
    this.setData({
      page: 1,
    }, () => {
      this.loadList();
    });
  },
  changeNav(e) {
    this.setData({
      page: 1,
      ctype: e.detail.obj.id,
    }, () => {
      this.loadList();
    });
  },
  loadList() {
    $util.request({
      url: 'entry/wxapp/partywork.index.gettasklist',
      data: {
        page: this.data.page,
        status: this.data.ctype,
      },
      success: (res) => {
        let list = res.data;
        if (this.data.page > 1) {
          list = [...this.data.list, ...list];
        }
        this.setData({
          list: list,
          page: this.data.page + 1,
          hasMore: res.data.length > 0,
        });
      },
    });
  },
  onReachBottom() {
    this.data.hasMore && this.loadList();
  },
});